package com.zx1316.javasimpledoudizhu.misc;

import static com.zx1316.javasimpledoudizhu.DDZApplication.INIT_CARD;

public record Card(String content) implements Comparable<Card> {
    @Override
    public int compareTo(Card card) {
        int i = 0;
        while (!content.equals(INIT_CARD[i])) {
            i++;
        }
        for (int j = 0; j < i; j++) {
            if (card.content().equals(INIT_CARD[j])) {
                return -1;
            }
        }
        return 1;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Card card) {
            return content.equals(card.content());
        }
        return false;
    }

    public int getRelative() {
        return switch (content.charAt(1)) {
            case 'B' -> 0;
            case 'S' -> 1;
            case '2' -> 2;
            case 'A' -> 3;
            case 'K' -> 4;
            case 'Q' -> 5;
            case 'J' -> 6;
            case '1' -> 7;
            case '9' -> 8;
            case '8' -> 9;
            case '7' -> 10;
            case '6' -> 11;
            case '5' -> 12;
            case '4' -> 13;
            default -> 14;
        };
    }
}
